#!/usr/bin/env python

import json
import types
import requests
import sys, os, inspect
from random import randint
from time import sleep

db = "m5s_fb_liked_pages.sqlite"
db_elected_details = "m5s_fb_elected_details.sqlite"

# This find path to additional modules in the same directory
# realpath() with make your script run, even if you symlink it :)
cmd_folder = os.path.realpath(os.path.abspath(os.path.split(inspect.getfile( inspect.currentframe() ))[0]))
if cmd_folder not in sys.path:
    sys.path.insert(0, cmd_folder)

# use this if you want to include modules from a subforder
cmd_subfolder = os.path.realpath(os.path.abspath(os.path.join(os.path.split(inspect.getfile( inspect.currentframe() ))[0],"subfolder")))
if cmd_subfolder not in sys.path:
    sys.path.insert(0, cmd_subfolder)

from fun import *
from local_info import *

list = queryDbForSourcePublicPages(db, db_elected_details)
for url in list:
    parsePublicPageDetails(db, url, ACCESS_TOKEN)
scrapePageLikesObject(db, ACCESS_TOKEN)
list = queryDbForLikedPublicPages(db)
counter = len(list)
for (user,) in list:
    print(counter)
    parsePublicPageDetails(db, user, ACCESS_TOKEN)
    counter -= 1
